﻿define(['RolePermissionList'], function (permissionList) {
    // 角色列表part
    var roleList = new Vue({
        el: "#vue",
        data: {
            pagination: {
                Filter: {},
                Datas: []
            }
        },
        ready: function () {
            this.find();
        },
        methods: {
            showRole: function (role) {
                roleEdit.show(role);
            },
            addRole: function () {
                roleEdit.show({});
            },
            find: function () {
                var that = this;
                $.post('', this.pagination.Filter).success(function (result) {
                    if (result.IsOk) {
                        that.pagination = result.Pagination;
                    }
                });
            },
            showPermissionPanel: function (role) {
                permissionList.showPermissionPanel(role);
            }
        }
    });

    // 角色编辑part
    var roleEdit = new Vue({
        el: '#roleInfo',
        data: {
            layerIndex: null,
            currentRole: {}
        },
        methods: {
            close: function () {
                layer.close(this.layerIndex);
                $('#roleInfo').hide();
            },
            show: function (role) {
                this.currentRole = $.extend({}, role);
                this.layerIndex = layer.open({
                    type: 1,
                    title: !role.Name ? "创建角色" : '编辑' + role.Name,
                    btn: false,
                    area: ['550px', '140px'],
                    closeBtn: false,
                    content: $('#roleInfo')
                });
            },
            save: function () {
                var that = this;
                $.post('/devRole/ModifyName', this.currentRole).success(function (result) {
                    if (result.IsOk) {
                        that.pagination = result.Pagination;
                        that.close();
                        roleList.find();
                    }
                });
            }
        }
    });
});
